package de.koller.worlders.engine.tiles.light.lights;

import de.koller.oceanFramework.gl.util.ImagePreview;
import de.koller.oceanFramework.gl.util.ParticleTexture;
import de.koller.oceanFramework.math.Vec;
import de.koller.oceanFramework.util.ColorIntUtil;
import de.koller.worlders.WorldersRoot;
import de.koller.worlders.engine.entity.IAABB;
import org.lwjgl.opengl.GL11;

public class OverlaySpot implements IOverlayLight {
	
	private ParticleTexture spot;
	private WorldersRoot wroot;
	
	@Override
	public void generate( WorldersRoot wroot ) {
		this.wroot = wroot;
		spot = ParticleTexture.generate( 255, 10 );
		
		for( int x = 0; x < 0xff-100; x++ )
			for( int y = 0; y < 10; y++ )
				spot.setPixel( ColorIntUtil.getIntColor( 0xff, 0xff-100-x, 0xff-100-x, 0xff-100-x ) , x, y);
		
		spot.flush();
		
		ImagePreview.showRaster( spot, 500, 100 );
	}

	@Override
	public void ungenerate() {
		
	}

	@Override
	public void renderThis() {
		IAABB p = wroot.gamePlayer.getGPO().getAABB();
		float px = p.getPosition().getXf() + p.getSize().getXf() * .5f;
		float py = p.getPosition().getYf() + p.getSize().getYf() * .5f;
		
		double r = wroot.getEntityContainer().getMouseWorldPosition().getDirection( new Vec( px, py ) );
		
		GL11.glPushMatrix();
		GL11.glTranslatef( px, py, 0 );
		GL11.glRotatef( (float)Math.toDegrees( r ), 0, 0, 1 );
		GL11.glTranslatef( -px, -py, 0 );
		
		spot.draw2D( px, py-.5f, 7, 1, 2 );
		GL11.glPopMatrix();
	}
	
}
